package com.example.idlefish.GoodsInfo

import android.os.Bundle
import android.util.Log
import com.example.idlefish.GoodsInfo.pojo.BuyInfo

import android.view.View

import androidx.appcompat.app.AppCompatActivity
import com.example.idlefish.GoodsInfo.ActivityContract.GooddResultContract
import com.example.idlefish.GoodsInfo.ActivityContract.ToHomePageContract
import com.example.idlefish.MyAccount.contract.HomepageContract
import com.example.idlefish.PublicModule.ApplicationConst
import com.example.idlefish.PublicModule.CommonUtil
import com.example.idlefish.PublicModule.UserConst
import com.example.idlefish.databinding.ActivityGoodOrderBinding

class GoodOrderActivity : AppCompatActivity() {
    private lateinit var binding:ActivityGoodOrderBinding
    private lateinit var  buyInfo:BuyInfo
    private val homeLauncher = registerForActivityResult(ToHomePageContract()){
            result->
    }
    private val homepageLauncher = registerForActivityResult(HomepageContract()) { result ->

    }
    private val goodContentLauncher = registerForActivityResult(GooddResultContract()){
            result->

    }
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityGoodOrderBinding.inflate(layoutInflater)
        setContentView(binding.root)
        binding.loadingtv3.visibility = View.VISIBLE
        binding.loading3.show()
        buyInfo = CommonUtil.getSerializable(intent, "buyInfo", BuyInfo::class.java)
        Log.i("buyinfo{}", buyInfo.toString())
        /////////
        Init()
        binding.goodOrderReturn.setOnClickListener {
            finish()
            homeLauncher.launch(Unit)
        }
        binding.returnHome.setOnClickListener {
            finish()
            homeLauncher.launch(Unit)
        }
        binding.concatSeller.setOnClickListener {
            finish()
            homepageLauncher.launch(UserConst.id)
        }
        binding.goodClick.setOnClickListener{
            goodContentLauncher.launch(buyInfo.goodId)
        }
    }
    fun Init()
    {
        binding.GoodAvater.setImageBitmap(ApplicationConst.goodPic1)
        binding.orderGoodCode.text  = buyInfo.orderCode
        binding.orderGoodTi.text = buyInfo.successTime
        binding.orderGoodAddress.text = buyInfo.address
        binding.orderGooodServicePrice.text = "¥" + ((buyInfo.price + buyInfo.postPrice) * 0.006f).toString()
        binding.orderGoodSinglePrice.text = "¥"+buyInfo.price.toString()
        binding.orderGoodPostPrice.text = "¥" + buyInfo.postPrice.toString()
        binding.orderGoodName.text = buyInfo.goodName
        binding.orderGoodPrice.text = "¥"+(buyInfo.price + buyInfo.postPrice).toString()
        binding.loadingtv3.visibility = View.GONE
        binding.loading3.hide()
    }
}